﻿using System;
using System.Windows.Data;

namespace Dsl.Ped.Common.Converters
{
    /// <summary>
    /// Converts by two defined converters, one by another
    /// </summary>
    public class CombiningConverter : IValueConverter
    {
        /// <summary>
        /// First converter to be applied
        /// </summary>
        public IValueConverter Converter1 { get; set; }

        /// <summary>
        /// Second converter to be applied
        /// </summary>
        public IValueConverter Converter2 { get; set; }

        #region Implementation of IValueConverter

        /// <summary>
        /// Converts by two defined converters, one by one
        /// </summary>
        /// <returns>Converter value by two converters</returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            object convertedValue = Converter1.Convert(value, targetType, parameter, culture);
            return Converter2.Convert(convertedValue, targetType, parameter, culture);
        }

        /// <summary>
        /// Backwards convertibility is not supported
        /// </summary>
        /// <exception cref="NotImplementedException">Backwards convertibility is not supported</exception>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
